<h1>IT Department Primer</h1>
<b>Generating PDF files in Symfony</b>
<br>
<br><a href="index.html">Back to Home</a>
<br>
<br>First, download the TCPDF package and put it in the same folder as your symfony programs. You can download it <a href="">here</a>, or go to __________.
<br>
<br>If you already have a symfony program you can try this on, go open its folder. Now, select a module that will generate the PDF file. Just imagine that we're building another action for that module. A normal action creates html for the browser. All we're doing now is creating an action to generate text content and putting that content it into a file.
<br>
<br>Go to that module's folder.
<br>
<br>First, open the actions/actions.class.php file and add 
<br>
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;executeShowpdf(sfWebRequest&nbsp;$request)
<br>&nbsp;&nbsp;{
<!--br>&nbsp;&nbsp;&nbsp;&nbsp;$this->ispdf=true;
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->executeShow($request);
<br>&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->download=$request->getParameter('download');-->
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->setLayout(false);
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->getResponse()->setContentType('pdf');
<br>&nbsp;&nbsp;}
<br>
<br>Naming the action executeShowpdf will cause your browser to generate the PDF file when the page /module/showpdf is requested. But you need to create the template first.
<br>The setLayout() is to hide the header information. We do not need to display the header inside the PDF file. 
<br>
<br>Now, create a template showpdfSuccess.php in the /templates folder, and paste the following code. Make sure there are no spaces or other text before the opening &lt;?php or after the closing ?&gt;. Feel free to delete the code that says "$pdf->Image" if you do not have access to quirinoseal.jpg, which should be in [symfonyprogram]/web/images. 
<br><hr>
&lt;?php
<br>$filename='hello.pdf';
<br>

<br>//this assumes that you placed the TCPDF folder in the same folder as your symfony program, preferably www. You are in www/[symfonyprogram]/web/index.php, so you go back up the directory tree twice to www, where tcpdf folder is located. You then enter tcpdf to find the files needed. If you do this incorrectly, your pdf file will not be generated, and a page not found error will appear.
<br>require_once('../../tcpdf/config/lang/eng.php');
<br>require_once('../../tcpdf/tcpdf.php');
<br>

<br>// create new PDF document
<br>$pdf = new TCPDF('P', PDF_UNIT, 'LEGAL', true, 'UTF-8', false);
<br>$pdf->SetTitle("Hello");
<br>
<br>//remove header & footer
<br>$pdf->setPrintHeader(false);
<br>$pdf->setPrintFooter(false);
<br>
<br>// set header and footer fonts
<br>//$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
<br>$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
<br>
<br>// set default monospaced font
<br>$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
<br>
<br>//set margins
<br>$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
<br>//$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
<br>$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
<br>
<br>//set auto page breaks
<br>$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
<br>
<br>//set image scale factor
<br>$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); 
<br>
<br>//set some language-dependent strings
<br>$pdf->setLanguageArray($l); 
<br>
<br>// ----CONTENT START-----------------------------------------------------
<br>
<br>// add a page
<br>$pdf->AddPage();
<br>
<br>//--------Header-------------------------
<br>
<br>//quirino&nbsp;seal&nbsp;image
<br>$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);&nbsp;
<br>$pdf->Image('images/quirinoseal.jpg',&nbsp;56,&nbsp;23,&nbsp;25,&nbsp;25);
<br>
<br>//Republic&nbsp;of&nbsp;the&nbsp;Philippines				
<br>//PROVINCE&nbsp;OF&nbsp;QUIRINO				
<br>//Cabarroguis				
<br>//o0o
<br>//
<br>//Provincial&nbsp;Government&nbsp;of&nbsp;Quirino
<br>$pdf->SetFont('helvetica',&nbsp;'',&nbsp;12);
<br>$content=array();
<br>$content[]=array('&nbsp;&nbsp;Republic&nbsp;of&nbsp;the&nbsp;Philippines');
<br>$content[]=array('&nbsp;&nbsp;PROVINCE&nbsp;OF&nbsp;QUIRINO');
<br>$content[]=array('&nbsp;&nbsp;Cabarroguis');
<br>$content[]=array('&nbsp;&nbsp;o0o');
<br>$content[]=array('');
<br>$content[]=array('Provincial&nbsp;Government&nbsp;of&nbsp;Quirino');
<br>foreach($content&nbsp;as&nbsp;$row)&nbsp;{
<br>	$pdf->Cell(0,&nbsp;6,&nbsp;$row[0],&nbsp;'',&nbsp;0,&nbsp;'C');
<br>	$pdf->Ln();
<br>	}
<br><br>// ----CONTENT END-----------------------------------------------------
<br>
<br>//create your pdf file for download
<br>$pdf->Output($filename, 'D');
<br>
<br>  ?><br>
<br><hr>
<br>Type http://localhost/[symfonyprogram]/showpdf in your browser.
<br>You should be asked by your browser to open or save a file. 
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>

